/**
 * 
 */
package test.action;

import java.util.List;

import quickstart.model.Person;
import test.pojo.Blog;
import test.service.BlogService;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Preparable;

/**
 * @author Ka
 *
 */
public class BlogAction implements Preparable {
	
	private BlogService service;
	private List<Blog> blogs;
	private Blog blog;
	private Integer id;

    public BlogAction(BlogService service) {
        this.service = service;
    }

    public String execute() {
        this.blogs = service.findAll();
        return Action.SUCCESS;
    }

    public String save() {
        this.service.save(blog);
        this.blog = new Blog();
        return execute();
    }

    public String remove() {
        service.remove(id);
        return execute();
    }

    public List<Blog> getBlogs() {
        return blogs;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void prepare() throws Exception {
        if (id != null)
        	blog = service.find(id);
    }

    public Blog getBlog() {
        return blog;
    }

    public void setBlog(Blog blog) {
        this.blog = blog;
    }


}
